package com.atguigu.spzx.manager.test;


import com.atguigu.spzx.common.vo.BaseEntity;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class CodeGet {

    public static void main(String[] args) {

        // 1、创建代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 2、全局配置
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir("E:\\workplace\\flyduck-study\\spzx-parent\\doc");

        gc.setServiceName("%sService");	//去掉Service接口的首字母I
        gc.setAuthor("flyduck");
        gc.setOpen(false);
        gc.setSwagger2(true);
        gc.setDateType(DateType.TIME_PACK);
        mpg.setGlobalConfig(gc);

        TemplateConfig templateConfig = new TemplateConfig();
        templateConfig.setService(null);
        mpg.setTemplate(templateConfig);

        // 3、数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/db_spzx?serverTimezone=GMT%2B8&useSSL=false");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("1234");
        dsc.setDbType(DbType.MYSQL);
        mpg.setDataSource(dsc);

        // 4、包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.atguigu.spzx");
        pc.setModuleName("product"); //模块名
        pc.setController("controller");
        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);

        // 5、策略配置
        StrategyConfig strategy = new StrategyConfig();

        strategy.setInclude("brand");
        strategy.setInclude("category");
        strategy.setInclude("category_brand");
        strategy.setInclude("coupon_info");
        strategy.setInclude("coupon_range");
        strategy.setInclude("coupon_user");
        strategy.setInclude("order_info");
        strategy.setInclude("order_item");
        strategy.setInclude("order_log");
        strategy.setInclude("order_statistics");
        strategy.setInclude("payment_info");
        strategy.setInclude("product");
        strategy.setInclude("product_attr");
        strategy.setInclude("product_details");
        strategy.setInclude("product_sku");
        strategy.setInclude("product_spec");
        strategy.setInclude("product_unit");
        strategy.setInclude("region");
        strategy.setInclude("sys_dept");
        strategy.setInclude("sys_login_log");
        strategy.setInclude("sys_menu");
        strategy.setInclude("sys_oper_log");
        strategy.setInclude("sys_post");
        strategy.setInclude("sys_role");
        strategy.setInclude("sys_role_menu");
        strategy.setInclude("sys_user");
        strategy.setInclude("sys_user_role");
        strategy.setInclude("user_address");
        strategy.setInclude("user_browse_history");
        strategy.setInclude("user_collect");
        strategy.setInclude("user_info");




        strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略

        strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
        strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作

        strategy.setRestControllerStyle(true); //restful api风格控制器
        strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符
        strategy.setSuperEntityClass(BaseEntity.class);
        strategy.setSuperEntityColumns("id","create_time","update_time","id_deleted");
        mpg.setStrategy(strategy);

        // 6、执行
        mpg.execute();
    }
}
